package com.hzsoft.resolver;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

public class RightsHandlerInterceptor extends HandlerInterceptorAdapter {
	/*
	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		String path = request.getServletPath();
		String menuId = null;
		HttpSession session = request.getSession();
		DcTblUser user = (DcTblUser) session.getAttribute(Const.SESSION_USER);
		if (path.matches(Const.NO_INTERCEPTOR_PATH)) {
			return true;
		} else {
			if (user == null) {
				response.sendRedirect(request.getContextPath()
						+ "/login.action");
				return false;
			} else {
				// 得到登录用户所用的可操作角色
				if ("admin".equals(user.getpLoginname())
						&& "admin".equals(user.getpUserid())
						&& "37".equals(user.getpRgid())) {
					return true;
				} else {
					
					String[] roleid = GlobalPrm.userforroleMap.get(user
							.getpUserid());
					if (roleid != null && roleid.length != 0) {
						for (int i = 0; i < roleid.length; i++) {
							// 菜单权限（在t_pw_menu表中P_TYPE为‘0’）
							List<TpwMenu> subList = GlobalPrm.menuMap
									.get(roleid[i]);
							if (subList != null && subList.size() != 0) {
								for (TpwMenu m : subList) {
									String menuUrl = m.getpUrl();
									if (Tools.notEmpty(menuUrl)) {
										if (path.contains(menuUrl)) {
											menuId = menuUrl;
											break;
										} else {
											String[] arr = menuUrl.split("\\.");
											String regex = "";
											if (arr.length == 2) {
												regex = "/?" + arr[0]
														+ "(/.*)?." + arr[1];

											} else {
												regex = "/?" + menuUrl
														+ "(/.*)?.action";
											}
											if (path.matches(regex)) {
												menuId = menuUrl;
												break;
											}
										}
									}
								}
							}
							// 按钮权限（在t_pw_menu表中P_TYPE为‘0’）
							List<TpwMenu> subList1 = GlobalPrm.OPERATIONMAP
									.get(roleid[i]);
							if (subList1 != null && subList1.size() != 0) {
								for (TpwMenu m : subList1) {
									String menuUrl = m.getpUrl();
									if (Tools.notEmpty(menuUrl)) {
										if (path.contains(menuUrl)) {
											menuId = menuUrl;
											break;
										} else {
											String[] arr = menuUrl.split("\\.");
											String regex = "";
											if (arr.length == 2) {
												regex = "/?" + arr[0]
														+ "(/.*)?." + arr[1];

											} else {
												regex = "/?" + menuUrl
														+ "(/.*)?.action";
											}
											if (path.matches(regex)) {
												menuId = menuUrl;
												break;
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
		if (menuId != null) {
			return true;
		} else {
			
			 response.setContentType("text/html;charset=UTF-8"); 
			 PrintWriter out = response.getWriter(); 
			 out.write("<script language=\"javascript\">\r\n");
			 out.println("alert('用户："+user.getpLoginname()+"试图访问"+path+"被阻止!');");
			 out.write("</script>");
			 
			return true;
		}
	   }
	}*/
}
